<?php

class DelController extends AdminController {
    
    private function deleteElem($redirectTo, $modelClass) {
        $model = CActiveRecord::model($modelClass)->findByPk($_GET['id']);
        if(!$model) throw new CHttpException(404, 'Не найдено указанной записи'); 
        if($model->delete()) $this->redirect($redirectTo);
        throw new CHttpException(500);
    }
    
//    public function actionUser($id) {
//        $this->deleteElem(array('default/user'), 'User');
//    }
    
    public function actionLogoMenu($id) {
        $this->deleteElem(array('default/logoMenu'), 'LogoMenu');
    }
    
    public function actionMainMenu($id) {
        $this->deleteElem(array('default/mainMenu'), 'MainMenu');
    }
    
    public function actionPage($id) {
        $this->deleteElem(array('default/page'), 'Page');
    }
    
    public function actionPartnerCat($id) {
        $this->deleteElem(array('default/partnerCat'), 'PartnerCat');
    }
    
    public function actionGroup($id) {
        $this->deleteElem(array('default/group'), 'Group');
    }
    
    public function actionPartner($id) {
        $this->deleteElem(array('default/partner'), 'Partner');
    }
    
    public function actionReview($id) {
        $this->deleteElem(array('default/redactor'), 'Reviews');
    }
    
    public function actionNews($id) {
        $this->deleteElem(array('default/news'), 'News');
    }
    
    public function actionMailing($id) {
        $this->deleteElem(array('default/mailing'), 'Mailing');
    }
    
    public function actionBlogCat($id) {
        $this->deleteElem(array('default/blogCat'), 'BlogCats');
    }
    
    public function actionBlogArt($id) {
        $this->deleteElem(array('default/blogArt'), 'BlogArts');
    }
    
    public function actionBanIp($id) {
        Yii::app()->db->createCommand()->delete('banned_ip', "`id`=$id");
        $this->redirect(array('default/banIp'));
    }
    
    public function actionPartErr($id) {
        Yii::app()->db->createCommand()->delete('error_reporting', "`id`=$id");
        $this->redirect(array('default/partErr'));
    }
    
    public function actionBanUser($id) {
        Yii::app()->db->createCommand()->update('users', array('isBanned'=>0, 'unblockDate'=>0), "`userid`=$id");
        $this->redirect(array('default/banUser'));
    }
    
    public function actionBrending($id) {
        $this->deleteElem(array('default/brending'), 'Brending');
    }
    
    public function actionSponsorAdt($id) {
        Yii::app()->db->createCommand()->delete('banners', 'bannerId='.$id);
        Yii::app()->db->createCommand()->delete('banners_relations', 'bannerId='.$id);
        $this->redirect(array('default/sponsorAdt'));
    }
    
    public function actionBannersBig($id) {
        Yii::app()->db->createCommand()->delete('banners_big', 'id='.$id);
        $this->redirect(array('default/bannersBig'));
    }
}